<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>InfIo</title>
<meta name="generator" content="DocBook XSL Stylesheets V1.76.0">
<link rel="home" href="index.html" title="libinfinity-0.4 Reference Manual">
<link rel="up" href="ch02.html" title="Common libinfinity API">
<link rel="prev" href="InfXmppManager.html" title="InfXmppManager">
<link rel="next" href="InfStandaloneIo.html" title="InfStandaloneIo">
<meta name="generator" content="GTK-Doc V1.15 (XML mode)">
<link rel="stylesheet" href="style.css" type="text/css">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table class="navigation" id="top" width="100%" summary="Navigation header" cellpadding="2" cellspacing="2">
<tr valign="middle">
<td><a accesskey="p" href="InfXmppManager.html"><img src="left.png" width="24" height="24" border="0" alt="Prev"></a></td>
<td><a accesskey="u" href="ch02.html"><img src="up.png" width="24" height="24" border="0" alt="Up"></a></td>
<td><a accesskey="h" href="index.html"><img src="home.png" width="24" height="24" border="0" alt="Home"></a></td>
<th width="100%" align="center">libinfinity-0.4 Reference Manual</th>
<td><a accesskey="n" href="InfStandaloneIo.html"><img src="right.png" width="24" height="24" border="0" alt="Next"></a></td>
</tr>
<tr><td colspan="5" class="shortcuts">
<a href="#InfIo.synopsis" class="shortcut">Top</a>
                   | 
                  <a href="#InfIo.description" class="shortcut">Description</a>
                   | 
                  <a href="#InfIo.object-hierarchy" class="shortcut">Object Hierarchy</a>
                   | 
                  <a href="#InfIo.prerequisites" class="shortcut">Prerequisites</a>
                   | 
                  <a href="#InfIo.implementations" class="shortcut">Known Implementations</a>
</td></tr>
</table>
<div class="refentry" title="InfIo">
<a name="InfIo"></a><div class="titlepage"></div>
<div class="refnamediv"><table width="100%"><tr>
<td valign="top">
<h2><span class="refentrytitle"><a name="InfIo.top_of_page"></a>InfIo</span></h2>
<p>InfIo — Event loop abstraction</p>
</td>
<td valign="top" align="right"></td>
</tr></table></div>
<div class="refsect1" title="Stability Level">
<a name="InfIo.stability-level"></a><h2>Stability Level</h2>
Unstable, unless otherwise indicated
</div>
<div class="refsynopsisdiv" title="Synopsis">
<a name="InfIo.synopsis"></a><h2>Synopsis</h2>
<pre class="synopsis">
#include &lt;libinfinity/common/inf-io.h&gt;

                    <a class="link" href="InfIo.html#InfIo-struct" title="InfIo">InfIo</a>;
                    <a class="link" href="InfIo.html#InfIoIface" title="InfIoIface">InfIoIface</a>;
typedef             <a class="link" href="InfIo.html#InfNativeSocket" title="InfNativeSocket">InfNativeSocket</a>;
enum                <a class="link" href="InfIo.html#InfIoEvent" title="enum InfIoEvent">InfIoEvent</a>;
<span class="returnvalue">void</span>                (<a class="link" href="InfIo.html#InfIoFunc" title="InfIoFunc ()">*InfIoFunc</a>)                        (<em class="parameter"><code><a class="link" href="InfIo.html#InfNativeSocket" title="InfNativeSocket"><span class="type">InfNativeSocket</span></a> *socket</code></em>,
                                                         <em class="parameter"><code><a class="link" href="InfIo.html#InfIoEvent" title="enum InfIoEvent"><span class="type">InfIoEvent</span></a> event</code></em>,
                                                         <em class="parameter"><code><a href="http://library.gnome.org/devel/glib/unstable/glib-Basic-Types.html#gpointer"><span class="type">gpointer</span></a> user_data</code></em>);
<span class="returnvalue">void</span>                (<a class="link" href="InfIo.html#InfIoTimeoutFunc" title="InfIoTimeoutFunc ()">*InfIoTimeoutFunc</a>)                 (<em class="parameter"><code><a href="http://library.gnome.org/devel/glib/unstable/glib-Basic-Types.html#gpointer"><span class="type">gpointer</span></a> user_data</code></em>);
<span class="returnvalue">void</span>                <a class="link" href="InfIo.html#inf-io-watch" title="inf_io_watch ()">inf_io_watch</a>                        (<em class="parameter"><code><a class="link" href="InfIo.html" title="InfIo"><span class="type">InfIo</span></a> *io</code></em>,
                                                         <em class="parameter"><code><a class="link" href="InfIo.html#InfNativeSocket" title="InfNativeSocket"><span class="type">InfNativeSocket</span></a> *socket</code></em>,
                                                         <em class="parameter"><code><a class="link" href="InfIo.html#InfIoEvent" title="enum InfIoEvent"><span class="type">InfIoEvent</span></a> events</code></em>,
                                                         <em class="parameter"><code><a class="link" href="InfIo.html#InfIoFunc" title="InfIoFunc ()"><span class="type">InfIoFunc</span></a> func</code></em>,
                                                         <em class="parameter"><code><a href="http://library.gnome.org/devel/glib/unstable/glib-Basic-Types.html#gpointer"><span class="type">gpointer</span></a> user_data</code></em>,
                                                         <em class="parameter"><code><a href="http://library.gnome.org/devel/glib/unstable/glib-Datasets.html#GDestroyNotify"><span class="type">GDestroyNotify</span></a> notify</code></em>);
<a href="http://library.gnome.org/devel/glib/unstable/glib-Basic-Types.html#gpointer"><span class="returnvalue">gpointer</span></a>            <a class="link" href="InfIo.html#inf-io-add-timeout" title="inf_io_add_timeout ()">inf_io_add_timeout</a>                  (<em class="parameter"><code><a class="link" href="InfIo.html" title="InfIo"><span class="type">InfIo</span></a> *io</code></em>,
                                                         <em class="parameter"><code><a href="http://library.gnome.org/devel/glib/unstable/glib-Basic-Types.html#guint"><span class="type">guint</span></a> msecs</code></em>,
                                                         <em class="parameter"><code><a class="link" href="InfIo.html#InfIoTimeoutFunc" title="InfIoTimeoutFunc ()"><span class="type">InfIoTimeoutFunc</span></a> func</code></em>,
                                                         <em class="parameter"><code><a href="http://library.gnome.org/devel/glib/unstable/glib-Basic-Types.html#gpointer"><span class="type">gpointer</span></a> user_data</code></em>,
                                                         <em class="parameter"><code><a href="http://library.gnome.org/devel/glib/unstable/glib-Datasets.html#GDestroyNotify"><span class="type">GDestroyNotify</span></a> notify</code></em>);
<span class="returnvalue">void</span>                <a class="link" href="InfIo.html#inf-io-remove-timeout" title="inf_io_remove_timeout ()">inf_io_remove_timeout</a>               (<em class="parameter"><code><a class="link" href="InfIo.html" title="InfIo"><span class="type">InfIo</span></a> *io</code></em>,
                                                         <em class="parameter"><code><a href="http://library.gnome.org/devel/glib/unstable/glib-Basic-Types.html#gpointer"><span class="type">gpointer</span></a> timeout</code></em>);
</pre>
</div>
<div class="refsect1" title="Object Hierarchy">
<a name="InfIo.object-hierarchy"></a><h2>Object Hierarchy</h2>
<pre class="synopsis">
  GInterface
   +----InfIo
</pre>
</div>
<div class="refsect1" title="Prerequisites">
<a name="InfIo.prerequisites"></a><h2>Prerequisites</h2>
<p>
InfIo requires
 <a href="http://library.gnome.org/devel/gobject/unstable/gobject-The-Base-Object-Type.html#GObject">GObject</a>.</p>
</div>
<div class="refsect1" title="Known Implementations">
<a name="InfIo.implementations"></a><h2>Known Implementations</h2>
<p>
InfIo is implemented by
 <a class="link" href="InfStandaloneIo.html" title="InfStandaloneIo">InfStandaloneIo</a>.</p>
</div>
<div class="refsect1" title="Description">
<a name="InfIo.description"></a><h2>Description</h2>
<p>
The <a class="link" href="InfIo.html" title="InfIo"><span class="type">InfIo</span></a> interface is used to schedule timeouts and to watch sockets for
events to occur. An actual implementation usually integrates this into the
application main loop, such as <a href="http://library.gnome.org/devel/glib/unstable/glib-The-Main-Event-Loop.html#GMainLoop"><span class="type">GMainLoop</span></a>. There is also a standalone
implementation, <a class="link" href="InfStandaloneIo.html" title="InfStandaloneIo"><span class="type">InfStandaloneIo</span></a>, that can directly be used as the
application's main loop.
</p>
<p>
Every object in Libinfinity that needs to schedule timeouts or watches
sockets uses a InfIo to do so. This allows to use libinfinity with
different main event loops, not only Glib's one.
</p>
</div>
<div class="refsect1" title="Details">
<a name="InfIo.details"></a><h2>Details</h2>
<div class="refsect2" title="InfIo">
<a name="InfIo-struct"></a><h3>InfIo</h3>
<pre class="programlisting">typedef struct _InfIo InfIo;</pre>
<p>
<a class="link" href="InfIo.html" title="InfIo"><span class="type">InfIo</span></a> is an opaque data type. You should only access it via the public
API functions.
</p>
</div>
<hr>
<div class="refsect2" title="InfIoIface">
<a name="InfIoIface"></a><h3>InfIoIface</h3>
<pre class="programlisting">typedef struct {
  void (*watch)(InfIo* io,
                InfNativeSocket* socket,
                InfIoEvent events,
                InfIoFunc func,
                gpointer user_data,
                GDestroyNotify notify);

  gpointer (*add_timeout)(InfIo* io,
                          guint msecs,
                          InfIoTimeoutFunc func,
                          gpointer user_data,
                          GDestroyNotify notify);

  void (*remove_timeout)(InfIo* io,
                         gpointer timeout);
} InfIoIface;
</pre>
<p>
The virtual methods of <a class="link" href="InfIo.html" title="InfIo"><span class="type">InfIo</span></a>. These allow to set up socket watches and
timeouts.
</p>
<div class="variablelist"><table border="0">
<col align="left" valign="top">
<tbody>
<tr>
<td><p><span class="term"><em class="structfield"><code><a name="InfIoIface.watch"></a>watch</code></em> ()</span></p></td>
<td>Changes the events the given socket is watched for. If <em class="parameter"><code>events</code></em> is
0, removes the watch for <em class="parameter"><code>socket</code></em>.
</td>
</tr>
<tr>
<td><p><span class="term"><em class="structfield"><code><a name="InfIoIface.add-timeout"></a>add_timeout</code></em> ()</span></p></td>
<td>Schedules <em class="parameter"><code>func</code></em> to be called at least <em class="parameter"><code>msecs</code></em> milliseconds
in the future.
</td>
</tr>
<tr>
<td><p><span class="term"><em class="structfield"><code><a name="InfIoIface.remove-timeout"></a>remove_timeout</code></em> ()</span></p></td>
<td>Removes a scheduled timeout again. The timeout is
removed automatically when it has elapsed, so there is no need to call
this function in that case.
</td>
</tr>
</tbody>
</table></div>
</div>
<hr>
<div class="refsect2" title="InfNativeSocket">
<a name="InfNativeSocket"></a><h3>InfNativeSocket</h3>
<p>
Native socket type on the target platform. This typedef is a simple <a href="/usr/share/gtk-doc/html/gnutls/gnutls-crypto.html#int"><span class="type">int</span></a>
on Unix and a <span class="type">SOCKET</span> on Windows.
</p>
</div>
<hr>
<div class="refsect2" title="enum InfIoEvent">
<a name="InfIoEvent"></a><h3>enum InfIoEvent</h3>
<pre class="programlisting">typedef enum _InfIoEvent {
  INF_IO_INCOMING = 1 &lt;&lt; 0,
  INF_IO_OUTGOING = 1 &lt;&lt; 1,
  INF_IO_ERROR    = 1 &lt;&lt; 2
} InfIoEvent;
</pre>
<p>
This enumeration specifies events that can be watched.
</p>
<div class="variablelist"><table border="0">
<col align="left" valign="top">
<tbody>
<tr>
<td><p><a name="INF-IO-INCOMING:CAPS"></a><span class="term"><code class="literal">INF_IO_INCOMING</code></span></p></td>
<td>Data can be read from the socket without blocking, or
the connection has been closed (which is the case when <code class="function">recv()</code> returns 0).
</td>
</tr>
<tr>
<td><p><a name="INF-IO-OUTGOING:CAPS"></a><span class="term"><code class="literal">INF_IO_OUTGOING</code></span></p></td>
<td>Data can be sent without blocking.
</td>
</tr>
<tr>
<td><p><a name="INF-IO-ERROR:CAPS"></a><span class="term"><code class="literal">INF_IO_ERROR</code></span></p></td>
<td>An error with the socket occured, or the connection has
been closed. Use <code class="function">getsockopt()</code> to read do <code class="literal">SO_ERROR</code> option to find out what
the problem is.
</td>
</tr>
</tbody>
</table></div>
</div>
<hr>
<div class="refsect2" title="InfIoFunc ()">
<a name="InfIoFunc"></a><h3>InfIoFunc ()</h3>
<pre class="programlisting"><span class="returnvalue">void</span>                (*InfIoFunc)                        (<em class="parameter"><code><a class="link" href="InfIo.html#InfNativeSocket" title="InfNativeSocket"><span class="type">InfNativeSocket</span></a> *socket</code></em>,
                                                         <em class="parameter"><code><a class="link" href="InfIo.html#InfIoEvent" title="enum InfIoEvent"><span class="type">InfIoEvent</span></a> event</code></em>,
                                                         <em class="parameter"><code><a href="http://library.gnome.org/devel/glib/unstable/glib-Basic-Types.html#gpointer"><span class="type">gpointer</span></a> user_data</code></em>);</pre>
<p>
Callback function that is called when an event occurs on a watched socket.
</p>
<div class="variablelist"><table border="0">
<col align="left" valign="top">
<tbody>
<tr>
<td><p><span class="term"><em class="parameter"><code>socket</code></em> :</span></p></td>
<td>The socket on which an event occured.
</td>
</tr>
<tr>
<td><p><span class="term"><em class="parameter"><code>event</code></em> :</span></p></td>
<td>A bitmask of the events that occured.
</td>
</tr>
<tr>
<td><p><span class="term"><em class="parameter"><code>user_data</code></em> :</span></p></td>
<td>User-defined data specified in <a class="link" href="InfIo.html#inf-io-watch" title="inf_io_watch ()"><code class="function">inf_io_watch()</code></a>.
</td>
</tr>
</tbody>
</table></div>
</div>
<hr>
<div class="refsect2" title="InfIoTimeoutFunc ()">
<a name="InfIoTimeoutFunc"></a><h3>InfIoTimeoutFunc ()</h3>
<pre class="programlisting"><span class="returnvalue">void</span>                (*InfIoTimeoutFunc)                 (<em class="parameter"><code><a href="http://library.gnome.org/devel/glib/unstable/glib-Basic-Types.html#gpointer"><span class="type">gpointer</span></a> user_data</code></em>);</pre>
<p>
Callback function that is called when a timeout has elapsed.
</p>
<div class="variablelist"><table border="0">
<col align="left" valign="top">
<tbody><tr>
<td><p><span class="term"><em class="parameter"><code>user_data</code></em> :</span></p></td>
<td>User-defined data specified in <a class="link" href="InfIo.html#inf-io-add-timeout" title="inf_io_add_timeout ()"><code class="function">inf_io_add_timeout()</code></a>.
</td>
</tr></tbody>
</table></div>
</div>
<hr>
<div class="refsect2" title="inf_io_watch ()">
<a name="inf-io-watch"></a><h3>inf_io_watch ()</h3>
<pre class="programlisting"><span class="returnvalue">void</span>                inf_io_watch                        (<em class="parameter"><code><a class="link" href="InfIo.html" title="InfIo"><span class="type">InfIo</span></a> *io</code></em>,
                                                         <em class="parameter"><code><a class="link" href="InfIo.html#InfNativeSocket" title="InfNativeSocket"><span class="type">InfNativeSocket</span></a> *socket</code></em>,
                                                         <em class="parameter"><code><a class="link" href="InfIo.html#InfIoEvent" title="enum InfIoEvent"><span class="type">InfIoEvent</span></a> events</code></em>,
                                                         <em class="parameter"><code><a class="link" href="InfIo.html#InfIoFunc" title="InfIoFunc ()"><span class="type">InfIoFunc</span></a> func</code></em>,
                                                         <em class="parameter"><code><a href="http://library.gnome.org/devel/glib/unstable/glib-Basic-Types.html#gpointer"><span class="type">gpointer</span></a> user_data</code></em>,
                                                         <em class="parameter"><code><a href="http://library.gnome.org/devel/glib/unstable/glib-Datasets.html#GDestroyNotify"><span class="type">GDestroyNotify</span></a> notify</code></em>);</pre>
<p>
Monitors the given socket for activity and calls <em class="parameter"><code>func</code></em> if one of the
events specified in <em class="parameter"><code>events</code></em> occurs.
</p>
<div class="variablelist"><table border="0">
<col align="left" valign="top">
<tbody>
<tr>
<td><p><span class="term"><em class="parameter"><code>io</code></em> :</span></p></td>
<td>A <a class="link" href="InfIo.html" title="InfIo"><span class="type">InfIo</span></a>.
</td>
</tr>
<tr>
<td><p><span class="term"><em class="parameter"><code>socket</code></em> :</span></p></td>
<td>The socket to watch.
</td>
</tr>
<tr>
<td><p><span class="term"><em class="parameter"><code>events</code></em> :</span></p></td>
<td>Events to watch for.
</td>
</tr>
<tr>
<td><p><span class="term"><em class="parameter"><code>func</code></em> :</span></p></td>
<td>Function to be called when one of the events occurs.
</td>
</tr>
<tr>
<td><p><span class="term"><em class="parameter"><code>user_data</code></em> :</span></p></td>
<td>Extra data to pass to <em class="parameter"><code>func</code></em>.
</td>
</tr>
<tr>
<td><p><span class="term"><em class="parameter"><code>notify</code></em> :</span></p></td>
<td>A <a href="http://library.gnome.org/devel/glib/unstable/glib-Datasets.html#GDestroyNotify"><span class="type">GDestroyNotify</span></a> that is called when <em class="parameter"><code>user_data</code></em> is no longer
needed, or <a href="http://library.gnome.org/devel/glib/unstable/glib-Standard-Macros.html#NULL:CAPS"><code class="literal">NULL</code></a>.
</td>
</tr>
</tbody>
</table></div>
</div>
<hr>
<div class="refsect2" title="inf_io_add_timeout ()">
<a name="inf-io-add-timeout"></a><h3>inf_io_add_timeout ()</h3>
<pre class="programlisting"><a href="http://library.gnome.org/devel/glib/unstable/glib-Basic-Types.html#gpointer"><span class="returnvalue">gpointer</span></a>            inf_io_add_timeout                  (<em class="parameter"><code><a class="link" href="InfIo.html" title="InfIo"><span class="type">InfIo</span></a> *io</code></em>,
                                                         <em class="parameter"><code><a href="http://library.gnome.org/devel/glib/unstable/glib-Basic-Types.html#guint"><span class="type">guint</span></a> msecs</code></em>,
                                                         <em class="parameter"><code><a class="link" href="InfIo.html#InfIoTimeoutFunc" title="InfIoTimeoutFunc ()"><span class="type">InfIoTimeoutFunc</span></a> func</code></em>,
                                                         <em class="parameter"><code><a href="http://library.gnome.org/devel/glib/unstable/glib-Basic-Types.html#gpointer"><span class="type">gpointer</span></a> user_data</code></em>,
                                                         <em class="parameter"><code><a href="http://library.gnome.org/devel/glib/unstable/glib-Datasets.html#GDestroyNotify"><span class="type">GDestroyNotify</span></a> notify</code></em>);</pre>
<p>
Calls <em class="parameter"><code>func</code></em> after at least <em class="parameter"><code>msecs</code></em> milliseconds have elapsed. The timeout
is removed after it has elapsed.
</p>
<div class="variablelist"><table border="0">
<col align="left" valign="top">
<tbody>
<tr>
<td><p><span class="term"><em class="parameter"><code>io</code></em> :</span></p></td>
<td>A <a class="link" href="InfIo.html" title="InfIo"><span class="type">InfIo</span></a>.
</td>
</tr>
<tr>
<td><p><span class="term"><em class="parameter"><code>msecs</code></em> :</span></p></td>
<td>Number of milliseconds after which the timeout should be elapsed.
</td>
</tr>
<tr>
<td><p><span class="term"><em class="parameter"><code>func</code></em> :</span></p></td>
<td>Function to be called when the timeout elapsed.
</td>
</tr>
<tr>
<td><p><span class="term"><em class="parameter"><code>user_data</code></em> :</span></p></td>
<td>Extra data to pass to <em class="parameter"><code>func</code></em>.
</td>
</tr>
<tr>
<td><p><span class="term"><em class="parameter"><code>notify</code></em> :</span></p></td>
<td>A <a href="http://library.gnome.org/devel/glib/unstable/glib-Datasets.html#GDestroyNotify"><span class="type">GDestroyNotify</span></a> that is called when <em class="parameter"><code>user_data</code></em> is no longer
needed, or <a href="http://library.gnome.org/devel/glib/unstable/glib-Standard-Macros.html#NULL:CAPS"><code class="literal">NULL</code></a>.
</td>
</tr>
<tr>
<td><p><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></p></td>
<td> A timeout handle that can be used to remove the timeout.
</td>
</tr>
</tbody>
</table></div>
</div>
<hr>
<div class="refsect2" title="inf_io_remove_timeout ()">
<a name="inf-io-remove-timeout"></a><h3>inf_io_remove_timeout ()</h3>
<pre class="programlisting"><span class="returnvalue">void</span>                inf_io_remove_timeout               (<em class="parameter"><code><a class="link" href="InfIo.html" title="InfIo"><span class="type">InfIo</span></a> *io</code></em>,
                                                         <em class="parameter"><code><a href="http://library.gnome.org/devel/glib/unstable/glib-Basic-Types.html#gpointer"><span class="type">gpointer</span></a> timeout</code></em>);</pre>
<p>
Removes the given timeout.
</p>
<div class="variablelist"><table border="0">
<col align="left" valign="top">
<tbody>
<tr>
<td><p><span class="term"><em class="parameter"><code>io</code></em> :</span></p></td>
<td>A <a class="link" href="InfIo.html" title="InfIo"><span class="type">InfIo</span></a>.
</td>
</tr>
<tr>
<td><p><span class="term"><em class="parameter"><code>timeout</code></em> :</span></p></td>
<td>A timeout handle obtained from <a class="link" href="InfIo.html#inf-io-add-timeout" title="inf_io_add_timeout ()"><code class="function">inf_io_add_timeout()</code></a>.
</td>
</tr>
</tbody>
</table></div>
</div>
</div>
<div class="refsect1" title="See Also">
<a name="InfIo.see-also"></a><h2>See Also</h2>
<a class="link" href="InfStandaloneIo.html" title="InfStandaloneIo"><span class="type">InfStandaloneIo</span></a>
</div>
</div>
<div class="footer">
<hr>
          Generated by GTK-Doc V1.15</div>
</body>
</html>